Ext.define('PJ.view.celabankmanagement.Edit', {
	extend: 'AM.default.DefaultWindowForm',
	requires: ['AM.default.jsonp.DefaultSubmitJsonp',
	           'AM.default.DefaultChooseField',
	           'AM.default.DefaultDateField',
	           'AM.default.DateTime'
	           ],

	modal: true,// 开启不允许点击其他组件
	frame: true,
	notEdit: true,
	isSame: false,
    width: 650,
    height:460,
	layout: 'form',
	overflowX: 'hidden',
    overflowY: 'scroll',
    flag: 0,
	initComponent: function(){
		var me = this;
		var bt = me.isReadOnly?"":'<span style="color:red;">*</span>';
		var tc = "options";
        var fz = "fzOptions";
        var xx = 'xxOptions';
		me.items = [{
			xtype: 'container',
			layout: 'column',
			itemId: 'tgqy',
    		width:612,
			defaults:{
				labelAlign: 'right',
				allowBlank: true,  //红框是否显示
				columnWidth: .98,
				labelWidth: 85,
				readOnly:me.isReadOnly
			},
			items:[{
                fieldLabel: bt + "试题题型",
                name: "questionType",
                xtype: "combo",
                columnWidth: .5,
                readOnly:me.isReadOnly,
                valueField: "value",
                displayField: "text",
                editable: false,
                queryMode: 'local', //'remote',
                value: "danxt",
                allowBlank: false,
                store: Ext.create("Ext.data.ArrayStore", {
                    singleton: true,
                    fields: [{
                        name: 'value',
                        mapping: "dataCode",
                        type: 'string'
                    }, {
                        name: 'text',
                        mapping: "dataName",
                        type: 'string'
                    }],
                    proxy: {
                        type: gj_onlineLearning_constant.loadType == "jsonp" ? gj_onlineLearning_constant.loadType:'ajax',
                        url : me.grid.getStore().typeUrl,
                        reader: Ext.create('Ext.data.reader.Json', {
                            type: 'json',
                            root: 'data',
                            successProperty: 'success'
                        })
                    },
                    autoLoad: true
                }),
                listeners: {
                    change: function(f, n, o){
                    	me.itemTypeChange(n);
                    }
                }
            },{
                fieldLabel: "试题题组",
                name: "questionsProblemSets",
                itemId: 'questionsProblemSets',
                xtype: "textfield",
                disabled: false,
                readOnly:me.isReadOnly,
                columnWidth: .5,
                //valueField: "value",
                //displayField: "text",
                //editable: false,
                //queryMode: 'local', //'remote',
                //value: "1",
                allowBlank: true,
                /*
                store: Ext.create("Ext.data.ArrayStore", {
                    fields: ['value', 'text'],
                    data: [['1', '培训设计'], ['2', '培训实施'], ['3', '培训管理'], ['4', '培训效果'], ['5', '意见建议']]
                }),
                */
                listeners: {
                    change: function(f, n, o){
                    	
                    }
                }
            },{
                fieldLabel: bt + "试题题干",
                name: 'questionName',
                xtype: 'textareafield',
                allowBlank: false,
                readOnly:me.isReadOnly,
                margin: '8 0 0 0',
                columnWidth: 1,
                rows: 6,
                maxLength: 120,
                maxLengthText: "题干最多可以输入120个中文字符或240个英文字符。",
                listeners: {
                    blur: function(){
                        this.setValue(this.getValue().trim());
                    }
                }
            }]
		},{
			xtype: 'container',
			layout: 'column',
			itemId: 'dxxxqy',
    		width:612,
			defaults:{
				labelAlign: 'right',
				allowBlank: true,  //红框是否显示
				columnWidth: .98,
				readOnly:me.isReadOnly,
				labelWidth: 85
			},
			items:[{
                fieldLabel: " ",
                xtype: "radiogroup",
                allowBlank: true,
                blankText: " ",
                labelSeparator: "",
                margin: "5 5 0 5",
                readOnly:me.isReadOnly,
                hidden: me.questionTypeFlag,
                isLimitModel: false,
                items: [{
                    name: "questionTypes",
                    boxLabel: "单选数值型",
                    inputValue: "1",
                    readOnly:me.isReadOnly,
                    checked: true,
                    itemId: "dxszx"
                }, {
                    name: "questionTypes",
                    boxLabel: "文字型",
                    inputValue: "2",
                    readOnly:me.isReadOnly,
                    itemId: "wzx"
                }],
                listeners: {
                    change: function(f, n, o){
                        var form = this.up("form");
                    	var tcID = form.down("#tcID");//文字型选项区域（多选）
                    	var fzID = form.down("#fzID");//数值型选项区域
                    	var xxID = form.down("#xxID");//文字型选项区域（单选）
                    	var danxanbtn = form.down("#danxanbtn");//单选按钮
                    	var duoxuanbtn = form.down("#duoxuanbtn");//多选按钮
                        if (n.questionTypes == 1) {
                        	fzID.show();
                        	danxanbtn.show();
                        	tcID.hide();
                        	xxID.hide();
                        	duoxuanbtn.hide();
                        	fzID.setDisabled(false);
                        	danxanbtn.setDisabled(false);
                        	tcID.setDisabled(true);
                        	xxID.setDisabled(true);
                        	duoxuanbtn.setDisabled(true);
                        }
                        else 
                            if (n.questionTypes == 2) {
                            	fzID.hide();
                            	danxanbtn.show();
                            	tcID.hide();
                            	xxID.show();
                            	duoxuanbtn.hide();
                            	fzID.setDisabled(true);
                            	danxanbtn.setDisabled(false);
                            	tcID.setDisabled(true);
                            	xxID.setDisabled(false);
                            	duoxuanbtn.setDisabled(true);
                            }
                    },
                    afterrender: function(){
                        //this.hide();
                    }
                }
            },{
                fieldLabel: " ",
                xtype: "radiogroup",
                allowBlank: true,
                blankText: " ",
                labelSeparator: "",
                margin: "5 5 0 5",
                readOnly:me.isReadOnly,
                hidden: me.questionTypeFlag,
                isLimitModel: false,
                items: [{
                    name: "questionTypes_",
                    boxLabel: "多选文字型",
                    readOnly:me.isReadOnly,
                    inputValue: "2",
                    itemId: "dxwzx",
                    checked: true,
                    listeners: {
                    	afterrender: function(){
                            this.hide();
                        }
                    }
                }]
            },{
            	xtype: 'container',
    			layout: 'column',
    			itemId: 'dxtxxsz',
    			items: [{	
                    fieldLabel: bt + "分值",
                    xtype: "fieldcontainer",
                    labelAlign: 'right',
                    itemId: "fzID",
                    id: "fzID",
                    readOnly:me.isReadOnly,
                    hidden: false,
                    layout: "column",
                    margin: "5 5 0 5",
                    width: 600,
                    defaults: {
                        xtype: "combo",
                        store: Ext.create("Ext.data.ArrayStore", {
                            fields: ['value', 'text'],
                            data: [['1', '1分'], ['2', '2分'], ['3', '3分'], ['4', '4分'], ['5', '5分']]
                        }),
                        valueField: 'value',
                        displayField: 'text',
                        editable: false,
                        emptyText: "请选择",
                        labelWidth: 15,
                        margin: "5 0",
                        columnWidth: 1,
                        listeners: {
                            blur: function(item){
                            	var form = me.down("form");
                            	//var fzIDlen = form.down("#fzID").items.items.length;
                                if (!Ext.isEmpty(item.getValue()) && item.tid) {
                                    item.allowBlank = false;
                                    //if (item.tid < (fzIDlen/2+1)) {
                                    if (item.tid < 3) {
                                        var nxt = this.up("fieldcontainer").down("#" + fz + (Number(item.tid) + 1)).enable();
                                        nxt.allowBlank = true;
                                    }
                                }
                            }
                        }
                    },
                    items: [{
                        name: tc,
                        fieldLabel: "A",
                        margin: "0 0 5 0",
                        itemId: fz + "0",
                        id: fz + "0",
                        readOnly:me.isReadOnly,
                        tid: "0",
                        allowBlank: true
                    }, {
                        name: tc,
                        fieldLabel: "B",
                        itemId: fz + "1",
                        readOnly:me.isReadOnly,
                        tid: "1",
                        disabled: true
                    }, {
                        name: tc,
                        fieldLabel: "C",
                        itemId: fz + "2",
                        tid: "2",
                        readOnly:me.isReadOnly,
                        disabled: true
                    }, {
                        name: tc,
                        fieldLabel: "D",
                        itemId: fz + "3",
                        readOnly:me.isReadOnly,
                        tid: "3",
                        disabled: true
                    }]
                },{
                    fieldLabel: bt + "选项",
                    xtype: "fieldcontainer",
                    labelAlign: 'right',
                    itemId: "xxID",
                    id: "xxID",
                    hidden: true,
                    readOnly:me.isReadOnly,
                    layout: "column",
                    margin: "5 5 0 5",
                    width: 600,
                    defaults: {
                        xtype: "textfield",
                        labelWidth: 15,
                        margin: "5 0",
                        columnWidth: 1,
                        listeners: {
                            blur: function(item){
                            	
                                if (!Ext.isEmpty(item.getValue()) && item.tid) {
                                    item.allowBlank = false;
                                    if (item.tid < 3) {
                                        var nxt = this.up("fieldcontainer").down("#" + xx + (Number(item.tid) + 1)).enable();
                                        nxt.allowBlank = true;
                                    }
                                }
                            }
                        }
                    },
                    items: [{
                        name: tc,
                        fieldLabel: "A",
                        margin: "0 0 5 0",
                        itemId: xx + "0",
                        id: xx + "0",
                        tid: "0",
                        readOnly:me.isReadOnly,
                        allowBlank: true
                    }, {
                        name: tc,
                        fieldLabel: "B",
                        itemId: xx + "1",
                        tid: "1",
                        readOnly:me.isReadOnly,
                        disabled: true
                    }, {
                        name: tc,
                        fieldLabel: "C",
                        itemId: xx + "2",
                        tid: "2",
                        readOnly:me.isReadOnly,
                        disabled: true
                    }, {
                        name: tc,
                        fieldLabel: "D",
                        itemId: xx + "3",
                        tid: "3",
                        readOnly:me.isReadOnly,
                        disabled: true
                    }]
                },{
                	xtype: 'container',
                	layout: 'column',
                	width:612,
                	itemId: 'danxanbtn',
                	items: [{
                    	xtype: 'button',
                        text: '添加选项',
                        columnWidth: .85,
                        margin: '0 5 0 405',
                        itemId: 'tjxx',
                        id: 'tjxx',
                        disabled:me.isReadOnly,
                        handler: function(button, event){
                            var form = button.up("form");
                            var xxID = form.down("#xxID");
                            var fzID = form.down("#fzID");
                            var dxszx = form.down("#dxszx");
                            var wzx = form.down("#wzx");
                            var tjxx = form.down("#tjxx");
                            if(dxszx.checked){
                            	var fzID_len = fzID.items.items.length;
                            	var E_Code="E".charCodeAt(0);
                            	if(fzID_len == 4){
                            		fzID.add({
                                        name: tc,
                                        fieldLabel: "E",
                                        itemId: xx + "4",
                                        tid: "4",
                                        columnWidth:.93,
                                        disabled: false
                                    },{
                                    	xtype: 'button',
                                    	iconCls: 'deleteIco',
                                    	tooltip: '删除',
                                    	columnWidth:.07,
                                    	margin: '5 0 0 5',
                                    	padding: '3 3 3 3',
                                    	handler: function(){
                                    		me.assignment(fzID,this);
                                    		tjxx.setDisabled(false);
                                    	},
                                    	listeners: {
                                            blur: function(item){}
                                        }
                                    });
                            	}else{
                            		var strCode = E_Code + (fzID_len-4)/2;
                            		var str = String.fromCharCode(strCode);
                            		if(str == "J"){
                            			button.setDisabled(true);
                            		}
                            		var idStr = 4 + (fzID_len-4)/2;
                            		fzID.add({
                                        name: tc,
                                        fieldLabel: str,
                                        itemId: xx + idStr,
                                        tid: idStr,
                                        columnWidth:.93,
                                        disabled: false
                                    },{
                                    	xtype: 'button',
                                    	iconCls: 'deleteIco',
                                    	tooltip: '删除',
                                    	columnWidth:.07,
                                    	margin: '5 0 0 5',
                                    	padding: '3 3 3 3',
                                    	handler: function(){
                                    		me.assignment(fzID,this);
                                    		tjxx.setDisabled(false);
                                    	},
                                    	listeners: {
                                            blur: function(item){}
                                        }
                                    });
                            	}
                            }else if(wzx.checked){
                            	var xxID_len = xxID.items.items.length;
                            	var E_Code="E".charCodeAt(0);
                            	if(xxID_len == 4){
                            		xxID.add({
                                        name: tc,
                                        fieldLabel: "E",
                                        itemId: fz + "4",
                                        tid: "4",
                                        columnWidth:.93,
                                        disabled: false
                                    },{
                                    	xtype: 'button',
                                    	iconCls: 'deleteIco',
                                    	tooltip: '删除',
                                    	columnWidth:.07,
                                    	margin: '5 0 0 5',
                                    	padding: '3 3 3 3',
                                    	handler: function(){
                                    		me.assignment(xxID,this);
                                    		tjxx.setDisabled(false);
                                    	},
                                    	listeners: {
                                            blur: function(item){}
                                        }
                                    });
                            	}else{
                            		var strCode = E_Code + (xxID_len-4)/2;
                            		var str = String.fromCharCode(strCode);
                            		if(str == "J"){
                            			button.setDisabled(true);
                            		}
                            		var idStr = 4 + (xxID_len-4)/2;
                            		xxID.add({
                                        name: tc,
                                        fieldLabel: str,
                                        itemId: fz + idStr,
                                        tid: idStr,
                                        columnWidth:.93,
                                        disabled: false
                                    },{
                                    	xtype: 'button',
                                    	iconCls: 'deleteIco',
                                    	tooltip: '删除',
                                    	columnWidth:.07,
                                    	margin: '5 0 0 5',
                                    	padding: '3 3 3 3',
                                    	handler: function(){
                                    		me.assignment(xxID,this);
                                    		tjxx.setDisabled(false);
                                    	},
                                    	listeners: {
                                            blur: function(item){}
                                        }
                                    });
                            	}
                            }
                        }
                    },{
                    	xtype: 'button',
                        text: '重置',
                        disabled:me.isReadOnly,
                        columnWidth: .15,
                        margin: '0 5 0 5',
                        itemId: 'chongz',
                        id: 'chongz',
                        handler: function(button, event){
                        	var form = button.up("form");
                            var xxID = form.down("#xxID");
                            var fzID = form.down("#fzID");
                            var dxszx = form.down("#dxszx");
                            var wzx = form.down("#wzx");
                            var tjxx = form.down("#tjxx");
                            if(dxszx.checked){
                            	var fzID_len = fzID.items.items.length;
                            	for(var i=fzID_len;i>3;i--){
                            		fzID.remove(fzID.items.items[i]);
                            	}
                            }else if(wzx.checked){
                            	var xxID_len = xxID.items.items.length;
                            	for(var i=xxID_len;i>3;i--){
                            		xxID.remove(xxID.items.items[i]);
                            	}
                            }
                            tjxx.setDisabled(false);
                        }
                    }]
                },{
                    fieldLabel: bt + "选项",
                    xtype: "fieldcontainer",
                    labelAlign: 'right',
                    itemId: "tcID",
                    id: "tcID",
                    hidden:true,
                    readOnly:me.isReadOnly,
                    layout: "column",
                    margin: "5 5 0 5",
                    defaults: {
                        xtype: "textfield",
                        labelWidth: 15,
                        margin: "5 0",
                        columnWidth: .5,
                        labelAlign: 'right',
                        listeners: {
                            blur: function(item){
                                var option = this.up("fieldcontainer").down("#" + tc + (Number(item.tid)));
                                option.setValue(option.getValue().trim());
                                if (!Ext.isEmpty(item.getValue()) && item.tid) {
                                    item.allowBlank = false;
                                    if (item.tid < 3) {
                                        var nxt = this.up("fieldcontainer").down("#" + tc + (Number(item.tid) + 1)).enable();
                                        nxt.allowBlank = true;
                                    }
                                }
                            }
                        }
                    },
                    items: [{
                        name: tc,
                        fieldLabel: "A",
                        margin: "0 0 5 0",
                        itemId: tc + "0",
                        id: tc + "0",
                        readOnly:me.isReadOnly,
                        tid: "0",
                        maxLength: 500,
                        maxLengthText: "该选项最多可以输入250个中文字符或500个英文字符。",
                        allowBlank: true
                    }, {
                        fieldLabel: "是否为主观题",
                        labelWidth: 85,
                        xtype: "radiogroup",
                        allowBlank: true,
                        blankText: " ",
                        readOnly:me.isReadOnly,
                        //labelSeparator: "",
                        margin: "5 5 0 5",
                        columnWidth: .43,
                        hidden: me.questionTypeFlag,
                        isLimitModel: false,
                        items: [{
                            name: "isSubjectiveQuestions_0",
                            boxLabel: "是",
                            readOnly:me.isReadOnly,
                            inputValue: "1"
                        }, {
                            name: "isSubjectiveQuestions_0",
                            boxLabel: "否",
                            readOnly:me.isReadOnly,
                            inputValue: "2",
                            checked: true
                        }]
                    }, {
                        name: tc,
                        margin: "0 0 5 0",
                        fieldLabel: "B",
                        itemId: tc + "1",
                        tid: "1",
                        maxLength: 500,
                        readOnly:me.isReadOnly,
                        maxLengthText: "该选项最多可以输入250个中文字符或500个英文字符。",
                        disabled: true
                    }, {
                        fieldLabel: "是否为主观题",
                        labelWidth: 85,
                        xtype: "radiogroup",
                        allowBlank: true,
                        blankText: " ",
                        readOnly:me.isReadOnly,
                        margin: "5 5 0 5",
                        columnWidth: .43,
                        hidden: me.questionTypeFlag,
                        isLimitModel: false,
                        items: [{
                            name: "isSubjectiveQuestions_1",
                            boxLabel: "是",
                            readOnly:me.isReadOnly,
                            inputValue: "1"
                        }, {
                            name: "isSubjectiveQuestions_1",
                            boxLabel: "否",
                            inputValue: "2",
                            readOnly:me.isReadOnly,
                            checked: true
                        }]
                    }, {
                        name: tc,
                        fieldLabel: "C",
                        margin: "0 0 5 0",
                        itemId: tc + "2",
                        readOnly:me.isReadOnly,
                        tid: "2",
                        maxLength: 500,
                        maxLengthText: "该选项最多可以输入250个中文字符或500个英文字符。",
                        disabled: true
                    }, {
                        fieldLabel: "是否为主观题",
                        labelWidth: 85,
                        xtype: "radiogroup",
                        allowBlank: true,
                        blankText: " ",
                        margin: "5 5 0 5",
                        readOnly:me.isReadOnly,
                        columnWidth: .43,
                        hidden: me.questionTypeFlag,
                        isLimitModel: false,
                        items: [{
                            name: "isSubjectiveQuestions_2",
                            boxLabel: "是",
                            readOnly:me.isReadOnly,
                            inputValue: "1"
                        }, {
                            name: "isSubjectiveQuestions_2",
                            boxLabel: "否",
                            readOnly:me.isReadOnly,
                            inputValue: "2",
                            checked: true
                        }]
                    }, {
                        name: tc,
                        margin: "0 0 5 0",
                        fieldLabel: "D",
                        readOnly:me.isReadOnly,
                        itemId: tc + "3",
                        tid: "3",
                        maxLength: 500,
                        maxLengthText: "该选项最多可以输入250个中文字符或500个英文字符。",
                        disabled: true
                    }, {
                        fieldLabel: "是否为主观题",
                        labelWidth: 85,
                        xtype: "radiogroup",
                        allowBlank: true,
                        readOnly:me.isReadOnly,
                        blankText: " ",
                        margin: "5 5 0 5",
                        columnWidth: .43,
                        hidden: me.questionTypeFlag,
                        isLimitModel: false,
                        items: [{
                            name: "isSubjectiveQuestions_3",
                            boxLabel: "是",
                            readOnly:me.isReadOnly,
                            inputValue: "1"
                        }, {
                            name: "isSubjectiveQuestions_3",
                            boxLabel: "否",
                            inputValue: "2",
                            readOnly:me.isReadOnly,
                            checked: true
                        }]
                    }]
                },{
                	xtype: 'container',
                	layout: 'column',
                	width:612,
                	hidden: true,
                	itemId: 'duoxuanbtn',
                	items: [{
                    	xtype: 'button',
                        text: '添加选项',
                        columnWidth: .85,
                        margin: '10 5 0 405',
                        itemId: 'tjxxwz',
                        id: 'tjxxwz',
                        disabled:me.isReadOnly,
                        handler: function(button, event){
                            var form = button.up("form");
                            var tcID = form.down("#tcID");
                        	var tcID_len = tcID.items.items.length;
                        	var E_Code="E".charCodeAt(0);
                        	var tjxxwz = form.down("#tjxxwz");
                        	if(tcID_len == 8){
                        		tcID.add({
                                    name: tc,
                                    fieldLabel: "E",
                                    margin: "0 0 5 0",
                                    itemId: tc + "4",
                                    tid: "4",
                                    maxLength: 500,
                                    maxLengthText: "该选项最多可以输入250个中文字符或500个英文字符。",
                                    disabled: false
                                }, {
                                    fieldLabel: "是否为主观题",
                                    labelWidth: 85,
                                    xtype: "radiogroup",
                                    allowBlank: false,
                                    blankText: " ",
                                    margin: "5 5 0 5",
                                    columnWidth:.43,
                                    hidden: me.questionTypeFlag,
                                    isLimitModel: false,
                                    items: [{
                                        name: "isSubjectiveQuestions_4",
                                        boxLabel: "是",
                                        inputValue: "1"
                                    }, {
                                        name: "isSubjectiveQuestions_4",
                                        boxLabel: "否",
                                        inputValue: "2",
                                        checked: true
                                    }]
                                },{
                                	xtype: 'button',
                                	iconCls: 'deleteIco',
                                	tooltip: '删除',
                                	columnWidth:.07,
                                	margin: '5 0 0 5',
                                	padding: '3 3 3 3',
                                	handler: function(){
                                		me.assignmentDXT(tcID,this);
                                		tjxxwz.setDisabled(false);
                                	},
                                	listeners: {
                                        blur: function(item){}
                                    }
                                });
                        	}else{
                        		var strCode = E_Code + (tcID_len+1)/3-3;
                        		var str = String.fromCharCode(strCode);
                        		if(str == "J"){
                        			button.setDisabled(true);
                        		}
                        		var idStr = 4 + (tcID_len+1)/3;
                        		tcID.add({
                                    name: tc,
                                    fieldLabel: str,
                                    margin: "0 0 5 0",
                                    itemId: tc + idStr,
                                    tid: idStr,
                                    maxLength: 500,
                                    maxLengthText: "该选项最多可以输入250个中文字符或500个英文字符。",
                                    disabled: false
                                }, {
                                    fieldLabel: "是否为主观题",
                                    labelWidth: 85,
                                    xtype: "radiogroup",
                                    allowBlank: true,
                                    blankText: " ",
                                    margin: "5 5 0 5",
                                    columnWidth:.43,
                                    hidden: me.questionTypeFlag,
                                    isLimitModel: false,
                                    items: [{
                                        name: "isSubjectiveQuestions_" + idStr,
                                        boxLabel: "是",
                                        inputValue: "1"
                                    }, {
                                        name: "isSubjectiveQuestions_" + idStr,
                                        boxLabel: "否",
                                        inputValue: "2",
                                        checked: true
                                    }]
                                },{
                                	xtype: 'button',
                                	iconCls: 'deleteIco',
                                	tooltip: '删除',
                                	columnWidth:.07,
                                	margin: '5 0 0 5',
                                	padding: '3 3 3 3',
                                	handler: function(){
                                		me.assignmentDXT(tcID,this);
                                		tjxxwz.setDisabled(false);
                                	},
                                	listeners: {
                                        blur: function(item){}
                                    }
                                });
                        	}
                        }
                    },{
                    	xtype: 'button',
                        text: '重置',
                        columnWidth: .15,
                        margin: '10 5 0 5',
                        disabled:me.isReadOnly,
                        itemId: 'chongzwz',
                        id: 'chongzwz',
                        handler: function(button, event){
                        	var form = button.up("form");
                            var tcID = form.down("#tcID");
                            var tjxxwz = form.down("#tjxxwz");
                            var tcID_len = tcID.items.items.length;
                        	for(var i=tcID_len;i>7;i--){
                        		tcID.remove(tcID.items.items[i]);
                        	}
                        	tjxxwz.setDisabled(false);
                        }
                    }]
                }]
            },{
            	xtype: 'container',
    			layout: 'column',
    			itemId: 'ydtpzqy',//简答题配置区域
    			width:612,
    			hidden: true,
    			items: [{
                    fieldLabel: "是否限制答案字数",
                    labelWidth: 125,
                    xtype: "radiogroup",
                    itemId: "isLimitNum",
                    allowBlank: true,
                    readOnly:me.isReadOnly,
                    blankText: "参考答案不允许为空！",
                    margin: "5 5 0 5",
                    isLimitModel: false,
                    columnWidth: .7,
                    items: [{
                        name: "isLimitNum",
                        boxLabel: "是",
                        readOnly:me.isReadOnly,
                        inputValue: "1",
                        itemId: "isLimitNum0"
                    }, {
                        name: "isLimitNum",
                        readOnly:me.isReadOnly,
                        boxLabel: "否",
                        inputValue: "2",
                        itemId: "isLimitNum1",
                        checked: true
                    }],
                    listeners: {
                        change: function(f, n, o){
                            
                            var form = this.up("form");
                                var wordNum = Ext.getCmp("wordNum1");
                                var wordNum2 = Ext.getCmp("wordNum2");
                                if (n.isLimitNum == 1) {
                                	wordNum.allowBlank = false;
                                	wordNum.setFieldLabel('<span style="color:red;">*</span>字数限制：字数上限为');
                                	wordNum.setDisabled(false);
                                	wordNum2.setDisabled(false);
                                }
                                else 
                                    if (n.isLimitNum == 2) {
                                    	wordNum.allowBlank = true;
                                    	wordNum.setFieldLabel('字数限制：字数上限为');
                                    	wordNum.setDisabled(true);
                                    	wordNum2.setDisabled(true);
                                    }
                        },
                        afterrender: function(){
                        }
                    }
                }, {
    				xtype: "numberfield",
    				fieldLabel: '字数限制：字数上限为',
    				labelSeparator: "",
    				name: "wordNum",
    				readOnly:me.isReadOnly,
    				itemId: "wordNum1",
    				id: "wordNum1",
    				disabled:true,
    				allowDecimals: false,
    				hideTrigger: true,
    				allowBlank: false,
                    blankText: "字数限制不允许为空！",
                    labelWidth: 135,
                    columnWidth: .4,
                    margin: "5 5 0 5",
                    listeners: {
                        afterrender: function(){
                        }
                    }
    			}, {
    				xtype: "label",
    				text: "个汉字",
    				readOnly:me.isReadOnly,
    				itemId: "wordNum2",
    				id: "wordNum2",
    				disabled:true,
    				columnWidth: .2,
    				margin: "5 0 0 5",
                    listeners: {
                        afterrender: function(){
                        }
                    }
    			}]
            }]
		}];
		this.buttons = [{
			text: '保存',
			scope: this,
			hidden: me.isReadOnly,
			handler: function(button, event){
				var win = button.up('window');
				win.sub(0);
			}
		}, {
			text: '发布',
			scope: this,
			hidden: me.isReadOnly || !me.flag,
			handler: function(button, event){
				var win = button.up('window');
				win.sub(1);
			}
		},{
			text: '取消',
			scope: this,
			handler: this.close
		}];
		// 初始化成功后加入token
		/*
		this.addListener("afterrender", function(win){
			win.saveToken();
		});
		*/
		this.callParent(arguments);
	},
    listeners: {
    	render: function(){
            this.show();
        },
        beforerender: function(){
            var me = this;
            if (!me.notEdit) {
            	var actionName = "load";//默认使用非JSONP的加载方法名“load”
                if(gj_onlineLearning_constant.loadType=="jsonp") {//根据模块的全局变量设置是否使用JSONP的方式请求数据
                	actionName= "loadJsonp";
                }
                me.down('form').getForm().doAction(actionName,{//使用doAction(action,{options})；方式加载数据
                    url: me.grid.getStore().perUpdateUrl,
                    params: {
                    	questionId:me.questionId
                    },
                    success:function(form,action){
                    	var selectData = action.result.data;//Ext.decode(action.response.responseText).data;
                        me.pushData(selectData);
                    }
                });
            };
        },
    	afterrender:function(){
    		var me = this;
    		me.itemTypeChange();
    	}
    },
    /**
     * 表单加载数据
     * @param data 待加载的数据
     */
    pushData: function(data){
    	var me = this;
    	var bt = me.isReadOnly?"":'<span style="color:red;">*</span>';
		var tc = "options";
        var fz = "fzOptions";
        var xx = 'xxOptions';
    	var questionType = data.questionType;//试题类型
    	var optionList = data.optionList;//试题选项集合
    	var form = me.down("form");
    	var tjxxwz = form.down("#tjxxwz");
    	var tjxx = form.down("#tjxx");
    	var dxszx = form.down("#dxszx");//单选数值型
    	var wzx = form.down("#wzx");//文字型 
    	var dxwzx = form.down("#dxwzx");//多选文字型
    	var dxtxxsz = form.down("#dxtxxsz");//单/多选数值型选项区域
    	var tcID = form.down("#tcID");//文字型选项区域（多选）
    	var fzID = form.down("#fzID");//数值型选项区域
    	var xxID = form.down("#xxID");//文字型选项区域（单选）
    	var ydtpzqy = form.down("#ydtpzqy");//简答题区域
    	var danxanbtn = form.down("#danxanbtn");//单选按钮
    	var duoxuanbtn = form.down("#duoxuanbtn");//多选按钮
    	var E_Code="E".charCodeAt(0);
    	if(questionType == "danxt"){
    		var isdxszx = data.isScoreType;
    		if(optionList.length > 4){
    			if(isdxszx == 1){
    				dxszx.setValue(true);
    				for(var i = 4; i < optionList.length; i++){
    					var strCode = E_Code + i - 4;
                		var str = String.fromCharCode(strCode);
                		if(str == "J"){
                			button.setDisabled(true);
                		}
                		var idStr = i;
                		fzID.add({
                            name: tc,
                            fieldLabel: str,
                            itemId: fz + idStr,
                            tid: idStr,
                            columnWidth:.93,
                            disabled: false
                        },{
                        	xtype: 'button',
                        	iconCls: 'deleteIco',
                        	tooltip: '删除',
                        	columnWidth:.07,
                        	margin: '5 0 0 5',
                        	padding: '3 3 3 3',
                        	handler: function(){
                        		me.assignment(fzID,this);
                        		tjxx.setDisabled(false);
                        	},
                        	listeners: {
                                blur: function(item){}
                            }
                        });
    				}
    			}else if(isdxszx == 2){
    				wzx.setValue(true);
    				for(var i = 4; i < optionList.length; i++){
    					var strCode = E_Code + i - 4;
                		var str = String.fromCharCode(strCode);
                		if(str == "J"){
                			button.setDisabled(true);
                		}
                		var idStr = i;
                		xxID.add({
                            name: tc,
                            fieldLabel: str,
                            itemId: xx + idStr,
                            tid: idStr,
                            columnWidth:.93,
                            disabled: false
                        },{
                        	xtype: 'button',
                        	iconCls: 'deleteIco',
                        	tooltip: '删除',
                        	columnWidth:.07,
                        	margin: '5 0 0 5',
                        	padding: '3 3 3 3',
                        	handler: function(){
                        		me.assignment(xxID,this);
                        		tjxx.setDisabled(false);
                        	},
                        	listeners: {
                                blur: function(item){}
                            }
                        });
    				}
    			}
    		}
    		for (var i = 0, lan = optionList.length; i < lan; i++) {
    			var tmct;
    			if(isdxszx == 1){
    				tmct = fzID.down("#fzOptions" + i);
    			}else {
    				tmct = xxID.down("#xxOptions" + i);
    			}
    			if(i < 4)
                tmct.enable();
                tmct.setValue(optionList[i].optionName);
                tmct.allowBlank = false;
                tmct.focus();
            }
    	}else if(questionType == "duoxt"){
    		var isdxszx = data.isScoreType;
    		var tcID = form.down("#tcID");
        	var tcID_len = tcID.items.items.length;
        	var num = 8;
    		if(optionList.length > 4){
    			for(var i = 4; i < optionList.length; i++){
    				var strCode = E_Code + i - 4;
    				var str = String.fromCharCode(strCode);
    				if(str == "J"){
    					button.setDisabled(true);
    				}
    				var idStr;
    				if(i==4){
    					idStr=i;
    				}else{
    					idStr=num;
    					num=num+1;
    				}
    				tcID.add({
    					name: tc,
    					fieldLabel: str,
    					margin: "0 0 5 0",
    					itemId: tc + i,
    					tid: i,
    					columnWidth: .5,
    					maxLength: 500,
    					maxLengthText: "该选项最多可以输入250个中文字符或500个英文字符。",
    					disabled: false
    				},{
                        fieldLabel: "是否为主观题",
                        labelWidth: 85,
                        xtype: "radiogroup",
                        allowBlank: false,
                        blankText: " ",
                        margin: "5 5 0 5",
                        columnWidth:.43,
                        hidden: me.questionTypeFlag,
                        isLimitModel: false,
                        items: [{
                            name: "isSubjectiveQuestions_"+idStr,
                            boxLabel: "是",
                            inputValue: "1"
                        }, {
                            name: "isSubjectiveQuestions_"+idStr,
                            boxLabel: "否",
                            inputValue: "2",
                            checked: true
                        }]
                    },{
    					xtype: 'button',
    					iconCls: 'deleteIco',
    					tooltip: '删除',
    					columnWidth:.07,
    					margin: '5 0 0 5',
    					padding: '3 3 3 3',
    					handler: function(){
                    		me.assignmentDXT(tcID,this);
                    		tjxxwz.setDisabled(false);
                    	},
    					listeners: {
    						blur: function(item){}
    					}
    				});
    			}
    		}
    		var numStr = 8;
    		for (var i = 0, lan = optionList.length; i < lan; i++) {
    			var tmct = tcID.down("#options" + i);
    			if(i<5){
    				number=i;
    			}else{
    				number=numStr;
    				numStr=numStr+1;
    			}
    			var sfwzgt = this.down("form").getForm().findField("isSubjectiveQuestions_" + number);
    			if(i < 4)
                tmct.enable();
                tmct.setValue(optionList[i].optionName);
                sfwzgt.setValue(optionList[i].objectiveTopic);
                tmct.allowBlank = false;
                tmct.focus();
            }
    	}
    },
    /**
     * 删除动态添加的选项--单选题
     * @param container 选项容器
     * @param item 当前的删除按钮
     */
    assignment: function(container,item){
    	var me = this;
    	var prev = item.prev();
    	var next = item.next();
    	if(next){
    		prev.setValue(next.getValue());
    		me.assignment(container,next.next());
    	}else{
    		container.remove(item);
    		container.remove(prev);
    	}
    },
    /**
     * 删除动态添加的选项--多选题
     * @param container 选项容器
     * @param item 当前的删除按钮
     */
    assignmentDXT: function(container,item){
    	var me = this;
    	var prev_xx = item.prev().prev();
    	var prev_zg = item.prev();
    	var next_xx = item.next();
    	if(next_xx){
    		var next_zg = item.next().next();
    		prev_xx.setValue(next_xx.getValue());
    		prev_zg.setValue(next_zg.getValue());
    		me.assignmentDXT(container, next_zg.next());
    	}else{
    		container.remove(item);
    		container.remove(prev_xx);
    		container.remove(prev_zg);
    	}
    },
    itemTypeChange: function(code){
    	var me = this;
    	if(!code){
    		code = "danxt";
    	}
    	var form = me.down("form");
    	var dxszx = form.down("#dxszx");//单选数值型
    	var wzx = form.down("#wzx");//文字型 
    	var dxwzx = form.down("#dxwzx");//多选文字型
    	var dxtxxsz = form.down("#dxtxxsz");//单/多选数值型选项区域
    	var tcID = form.down("#tcID");//文字型选项区域（多选）
    	var fzID = form.down("#fzID");//数值型选项区域
    	var xxID = form.down("#xxID");//文字型选项区域（单选）
    	var ydtpzqy = form.down("#ydtpzqy");//简答题区域
    	var danxanbtn = form.down("#danxanbtn");//单选按钮
    	var duoxuanbtn = form.down("#duoxuanbtn");//多选按钮
    	var questionsProblemSets = form.down("#questionsProblemSets");//试题提组
    	if(code == "danxt"){
    		this.setHeight(460)
    		dxszx.show();
    		wzx.show();
    		if(dxszx.checked){
    			fzID.show();
    			xxID.hide();
    			fzID.setDisabled(false);
    			xxID.setDisabled(true);
    			Ext.each(xxID.items.items, function(item){
            		item.allowBlank = true;
            	});
    		}else{
    			fzID.hide();
    			xxID.show();
    			fzID.setDisabled(true);
    			xxID.setDisabled(false);
    			Ext.each(fzID.items.items, function(item){
            		item.allowBlank = true;
            	});
    		}
    		dxwzx.hide();
    		dxtxxsz.show();
    		tcID.hide();
    		ydtpzqy.hide();
    		danxanbtn.show();
    		duoxuanbtn.hide();
    		dxszx.setDisabled(false);
    		wzx.setDisabled(false);
    		dxwzx.setDisabled(true);
    		tcID.setDisabled(true);
    		ydtpzqy.setDisabled(true);
    		danxanbtn.setDisabled(false);
    		duoxuanbtn.setDisabled(true);
    		Ext.each(tcID.items.items, function(item){
        		item.allowBlank = true;
        	});
    		questionsProblemSets.setDisabled(false);
    		questionsProblemSets.show();
    	}else if(code == "duoxt"){
    		this.setHeight(460)
    		dxszx.hide();
    		wzx.hide();
    		dxwzx.show();
    		dxtxxsz.show();
    		tcID.show();
    		fzID.hide();
    		xxID.hide();
    		ydtpzqy.hide();
    		danxanbtn.hide();
    		duoxuanbtn.show();
    		dxszx.setDisabled(true);
    		wzx.setDisabled(true);
    		dxwzx.setDisabled(false);
    		fzID.setDisabled(true);
    		xxID.setDisabled(true);
    		tcID.setDisabled(false);
    		ydtpzqy.setDisabled(true);
    		danxanbtn.setDisabled(true);
    		duoxuanbtn.setDisabled(false);
    		Ext.each(fzID.items.items, function(item){
        		item.allowBlank = true;
        	});
    		Ext.each(xxID.items.items, function(item){
        		item.allowBlank = true;
        	});
    		questionsProblemSets.setDisabled(true);
    		questionsProblemSets.hide();
    	}else if(code == "wendt"){
    		this.setHeight(300)
    		dxszx.hide();
    		wzx.hide();
    		dxwzx.hide();
    		dxtxxsz.hide();
    		tcID.hide();
    		fzID.hide();
    		xxID.hide();
    		ydtpzqy.show();
    		danxanbtn.hide();
    		duoxuanbtn.hide();
    		dxszx.setDisabled(true);
    		wzx.setDisabled(true);
    		dxwzx.setDisabled(true);
    		fzID.setDisabled(true);
    		xxID.setDisabled(true);
    		tcID.setDisabled(true);
    		ydtpzqy.setDisabled(false);
    		danxanbtn.setDisabled(true);
    		duoxuanbtn.setDisabled(true);
    		Ext.each(tcID.items.items, function(item){
        		item.allowBlank = true;
        	});
    		Ext.each(fzID.items.items, function(item){
        		item.allowBlank = true;
        	});
    		Ext.each(xxID.items.items, function(item){
        		item.allowBlank = true;
        	});
    		questionsProblemSets.setDisabled(true);
    		questionsProblemSets.hide();
    	}
    	
    },
    sub: function(n){
        var win = this;
        var form = win.down('form');
        var baseForm = form.getForm();
        if (!baseForm.isValid()) {
            return;
        }
        var url = "";
        if (this.notEdit) {
            url = win.grid.getStore().addUrl;
        }
        else {
            url = win.grid.getStore().updateUrl;
        }
        var tcID = form.down("#tcID");
        var optionsCollection = new Array();
        if(!tcID.isDisabled()){
        	var tcIDArray = tcID.items.items;
        	var tcID_len = tcIDArray.length;
        	if(tcID_len == 8){
        		var num = 0;
        		for(var i = 0;i<4;i++){
        			var isSQ = baseForm.findField("isSubjectiveQuestions_" + i).checked;
        			if(isSQ){
        				if(tcIDArray[num].value!=null||tcIDArray[num].value!=undefined){
        					optionsCollection.push(tcIDArray[num].value+"@sp@"+1);
        				}
        			}else{
        				if(tcIDArray[num].value!=null||tcIDArray[num].value!=undefined){
        					optionsCollection.push(tcIDArray[num].value+"@sp@"+2);
        				}
        			}
        			num = num+2;
        		}
        	}else if(tcID_len > 8){
        		var num = 0;
        		for(var i = 0;i<5;i++){
        			var isSQ = baseForm.findField("isSubjectiveQuestions_" + i).checked;
        			if(isSQ){
        				if(tcIDArray[num].value!=null||tcIDArray[num].value!=undefined){
        					optionsCollection.push(tcIDArray[num].value+"@sp@"+1);
        				}
        			}else{
        				if(tcIDArray[num].value!=null||tcIDArray[num].value!=undefined){
        			 		optionsCollection.push(tcIDArray[num].value+"@sp@"+2);
        				}
        			}
        			num = num+2;
        		}
        		var n = 8;
        		var J = 11;
        		for(var i = 4; i<(tcID_len+1)/3;i++){
        			var isSQ;
        			if(i == 4){
        				isSQ = baseForm.findField("isSubjectiveQuestions_" + n).checked;
        			}else{
        				isSQ = baseForm.findField("isSubjectiveQuestions_" + n).checked;
        			}
        			if(isSQ){
        				if(tcIDArray[num].value!=null||tcIDArray[J].value!=undefined){
        					optionsCollection.push(tcIDArray[J].value+"@sp@"+1);
        				}
        			}else{
        				if(tcIDArray[num].value!=null||tcIDArray[J].value!=undefined){
        					optionsCollection.push(tcIDArray[J].value+"@sp@"+2);
        				}
        			}
        			J = J+3;
        			n++;
        		}
        	}
        }
        var questionId = win.questionId;
        var questionnaireId = win.questionnaireId;
        if(gj_onlineLearning_constant.loadType=="jsonp"){
        	form.getForm().doAction('submitJsonp',{
        		url: url,
        		params: {
//        			isSubjectiveQuestions: isSubjectiveQuestions,
        			questionId:questionId,
        			questionnaireId:questionnaireId,
        			optionsCollection:optionsCollection
        		},
        		success: function(f, action){
        			if (action.result.success) {
        				Ext.Msg.alert('消息', "操作成功", function(){
        					win.close();
        					win.grid.getStore().reload();
        				});
        			}
        		},
        		failure: function(f, action){
        			if (action.result) {
        				Ext.Msg.alert('错误', action.result.msg, function(){
        				});
        			}else {
        				Ext.Msg.alert('错误', "操作失败", function(){
        				});
        			}
        		}
        	});
        }else if(gj_onlineLearning_constant.loadType=="ajax"){
        	win.submit({
                url: url,
                params: {
//                	isSubjectiveQuestions: isSubjectiveQuestions,
                	questionId:questionId,
                	questionnaireId:questionnaireId,
                	optionsCollection:optionsCollection
                },
                success: function(f, action){
                    if (action.result.success) {
                        Ext.Msg.alert('消息', action.result.msg, function(){
                            win.close();
                            win.grid.getStore().reload();
                        });
                    }
                },
                failure: function(f, action){
                    if (action.result) {
                        Ext.Msg.alert('错误', action.result.msg);
                    }
                    else {
                        Ext.Msg.alert('错误', "操作失败");
                    }
                }
            });
        }
    }
});
